using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using Meebey.SmartIrc4net;
using Thunder.IrcClient.Properties;

namespace Thunder.IrcClient.MessageParser.Default
{
    /// <summary>
    /// Handles the Join message 
    /// </summary>
    internal class MessageParserPart : MessageParser
    {
        /// <summary>
        /// Gets the type of message handled by the parser
        /// </summary>
        public override ReceiveType MessageType
        {
            get { return ReceiveType.Part; }
        }

        /// <summary>
        /// This method is invoked during message parsing.
        /// </summary>
        /// <param name="args">The <see cref="CancelMessageProcessingEventArgs"/> containing the message to be passed</param>
        /// <remarks>You can cancel further processing of the message by setting the <see cref="CancelEventArgs.Cancel"/> to true</remarks>
        protected override void ParseCore(CancelMessageProcessingEventArgs args)
        {
            if (Settings.Default.ShowJoinPart == false)
            {
                return;
            }

            if (this.Manager.IrcClient.IsMe(args.MessageData.Nick) == true)
            {
                this.Manager.CloseChannel(args.MessageData.Channel);
            }
            else
            {
                this.Manager.WriteText(args.MessageData.Channel, string.Format(CultureInfo.CurrentCulture, Localized.ChannelPart, args.MessageData.Nick), Colors.DarkGreen, FontWeights.Normal, FontStyles.Italic);
            }
        }
    }
}